<template>
  <div id="app">
    <!-- 侧边栏 -->
    <el-container class="app-container">
      <el-aside :width="isCollapse ? '64px' : '200px'" class="sidebar">
        <div class="logo">
          <h3 v-show="!isCollapse">Vue子应用</h3>
          <el-icon v-show="isCollapse"><ElementPlus /></el-icon>
        </div>
        <el-menu
          :default-active="activeMenu"
          class="sidebar-menu"
          :collapse="isCollapse"
          router
        >
          <el-menu-item index="/">
            <el-icon><House /></el-icon>
            <template #title>首页</template>
          </el-menu-item>
          <el-menu-item index="/products">
            <el-icon><Goods /></el-icon>
            <template #title>商品管理</template>
          </el-menu-item>
          <el-menu-item index="/orders">
            <el-icon><List /></el-icon>
            <template #title>订单管理</template>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 主内容区域 -->
      <el-container>
        <el-header class="header">
          <div class="header-left">
            <el-button
              type="text"
              @click="toggleCollapse"
              class="collapse-btn"
            >
              <el-icon><Fold v-if="!isCollapse" /><Expand v-else /></el-icon>
            </el-button>
            <h3>Vue子应用 - 基于Vue 3 + Element Plus</h3>
          </div>
          <div class="header-right">
            <el-tag v-if="mainAppData" type="success">
              来自主应用: {{ mainAppData }}
            </el-tag>
          </div>
        </el-header>
        
        <el-main class="main-content">
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'

/**
 * Vue子应用主组件
 * @description 提供Vue子应用的主要界面和布局
 */
export default {
  name: 'App',
  props: {
    mainAppData: {
      type: String,
      default: ''
    }
  },
  setup() {
    const route = useRoute()
    const isCollapse = ref(false)
    
    // 计算当前激活的菜单项
    const activeMenu = computed(() => route.path)
    
    // 切换侧边栏折叠状态
    const toggleCollapse = () => {
      isCollapse.value = !isCollapse.value
    }
    
    return {
      isCollapse,
      activeMenu,
      toggleCollapse
    }
  }
}
</script>

<style scoped>
/* Vue子应用样式 */
.app-container {
  height: 100vh;
}

/* 侧边栏样式 */
.sidebar {
  background: #304156;
  transition: width 0.3s;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  border-bottom: 1px solid #435266;
}

.logo h3 {
  margin: 0;
  font-weight: 600;
}

.sidebar-menu {
  border: none;
  background: #304156;
}

.sidebar-menu .el-menu-item {
  color: #bfcbd9;
}

.sidebar-menu .el-menu-item:hover,
.sidebar-menu .el-menu-item.is-active {
  background: #263445;
  color: #409eff;
}

/* 头部样式 */
.header {
  background: white;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.header-left {
  display: flex;
  align-items: center;
}

.collapse-btn {
  margin-right: 16px;
  font-size: 18px;
}

.header-left h3 {
  margin: 0;
  color: #303133;
}

.header-right {
  display: flex;
  align-items: center;
}

/* 主内容区域样式 */
.main-content {
  background: #f5f7fa;
  padding: 20px;
}
</style> 